/**
 * Created by ljg on 2017/3/27.
 */
import uiFormInput from './uiforminput';
import uiFormSelect from './uiformselect'
import uiFormSelectRemote from './uiformselectremote'
import uiFormRegion from './uiformregion'
import uiFormDate from './uiformdate'
import uiFormTextarea from './uiformtextarea'

const uiForm=function () {
    angular.module('ui.form',['ui.help']);
    uiFormInput();
    uiFormSelect();
    uiFormSelectRemote();
    uiFormRegion();
    uiFormDate();
    uiFormTextarea();
    angular.module('ui.form')
        .directive('uiForm', function (eventHelper) {
            return {
                restrict: 'E',
                replace: true,
                transclude: true,
                controller:function ($scope,$attrs) {
                    this._spliceColumn=function () {
                        return $attrs.column;
                    };
                },
                scope:{},
                template: function(el,attr){
                    return '<div class="panel-body">' +
                                '<form role="form" id='+attr.key+'>' +
                                        '<div class="row" ng-transclude></div>'+
                                        '<Button  class="btn btn-info" ng-click="submitForm()" >提交</Button>'+
                                '</form>' +
                            '</div>';
                },
                link : function(scope, element, attrs,ctrl) {
                        scope.submitForm=function () {
                            const formParam=$(element).find('form').serializeArray()||[];
                            const pageParam={};
                            formParam.map(f=>{
                                if(f.value!=""){
                                    pageParam[f.name]=f.value;
                                }
                            });
                            eventHelper.upperNotice(scope,'ui.form.submit',pageParam)
                        }
                },
            };
        });
}
export default uiForm;
